package com.ynunicom.dc.dingdingcontractapp.controller;

import com.alibaba.fastjson.JSONObject;
import com.ynunicom.dc.dingdingcontractapp.dto.ResponseDto;
import com.ynunicom.dc.dingdingcontractapp.dto.exception.ParamNullException;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.PageRequestEntity;
import com.ynunicom.dc.dingdingcontractapp.entity.StandReturnerImpl;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.TransBody;
import com.ynunicom.dc.dingdingcontractapp.service.CompanyOptionService;
import com.ynunicom.dc.dingdingcontractapp.service.impl.CompanyOptionServiceImpl;
import lombok.SneakyThrows;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: jinye.Bai
 * @date: 2020/5/26 15:04
 */

@RequestMapping("/comp")
@RestController
public class CompanyOptionController {

    @Resource
    CompanyOptionService companyOptionService;

    private static Class<?> companyOptionServiceClass = CompanyOptionServiceImpl.class;

    /**
     *
     * @param onlyActive 0：包含未激活钉钉的人员数量
     *                   1：不包含未激活钉钉的人员数量
     * @param access_token
     * @return
     */
    @SneakyThrows
    @ResponseStatus(HttpStatus.ACCEPTED)
    @GetMapping("/getStaffCount/{onlyActive}")
    public ResponseDto<JSONObject> getStaffCount(@PathVariable("onlyActive") String onlyActive,@RequestParam(value = "access_token",required = true) String access_token){
        TransBody<String> transBody = new TransBody<>(onlyActive,access_token);
        return new StandReturnerImpl().doReturn(transBody,companyOptionServiceClass,companyOptionServiceClass.getMethod("getStaffCount",TransBody.class));
    }

    @SneakyThrows
    @ResponseStatus(HttpStatus.ACCEPTED)
    @PostMapping("/getUnloginStaffList")
    public ResponseDto<JSONObject> getUnloginStaffList(@RequestParam("access_token") String access_token,@RequestBody @Validated PageRequestEntity pageRequestEntity){
        if(pageRequestEntity.getQuery_date().isEmpty()){
            throw new ParamNullException("query_date不能为空");
        }
        TransBody<PageRequestEntity> transBody = new TransBody<>(pageRequestEntity,access_token);
        return new StandReturnerImpl().doReturn(transBody,companyOptionServiceClass,companyOptionServiceClass.getMethod("getUnloginStaffList",TransBody.class));
    }
}
